﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Web.UI.DataVisualization.Charting;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UReturnVisitReportPage : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "UReturnVisitReport";
            }
        }
        #region 属性 (查询条件)


        protected string CreateDateFrom
        {
            get
            {
                return GetRequestValue<string>("CreateDateFrom", DateTime.Now.ToString("yyyy-MM-01"));

            }
        }

        protected string CreateDateTo
        {
            get
            {
                return GetRequestValue<string>("CreateDateTo", DateTime.Now.ToString("yyyy-MM-dd"));
            }
        }

       

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {            
            DataBind2();
        }
        

        protected void DataBind2()
        {
            DataTableCollection dts = UReturnVisitController.GetReport(CreateDateFrom, CreateDateTo);
           //dt.se
            DataTable dt = dts[0];
            //UReturnVisistChart.DataSource = dt;
            //UReturnVisistChart.DataBind();
            //UReturnVisistChart.DataSource = dt.Select("itemtype>=1");
            //UReturnVisistChart.Series["Series1"].XValueMember = "item";
            //UReturnVisistChart.Series["Series1"].YValueMembers = "pcount";
            //UReturnVisistChart.DataBind();
            UReturnVisistChart.Series["Series1"]["DrawingStyle"] = "Cylinder";
            UReturnVisistChart.Series["Series1"]["PointWidth"] = "0.3";

            DataRow[] drs = dt.Select("itemtype>=1");
            int i = 0;
            foreach (DataRow dr in drs)
            {
                DataPoint dp = new DataPoint();
                dp.AxisLabel =  dr["item"].ToString();
                dp.YValues = new double[] { Convert.ToDouble(dr["pcount"].ToString()) };
                
                UReturnVisistChart.Series["Series1"].Points.Add(dp);
               // UReturnVisistChart.Series["Series1"].Points[i].AxisLabel = dr["item"].ToString();
                //UReturnVisistChart.Series["Series1"].Points[i].YValues = new double[] { Convert.ToDouble(dr["pcount"].ToString()) };
                i++;
            }

            UReturnVisistChart.Titles["TaskTimeTitle"].Text = string.Format("共回访了{0}台机器", Convert.ToInt32( dt.Select("itemtype=0")[0]["pcount"]));

            Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
            System.Threading.Thread.Sleep(RandomNum_First.Next(50));
            Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
            int int_Red = RandomNum_First.Next(256);
            int int_Green = RandomNum_Sencond.Next(256);
            //int int_Blue = RandomNum_Sencond.Next(256);
            //  为了在白色背景上显示，尽量生成深色 
            int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
            int_Blue = (int_Blue > 255) ? 255 : int_Blue;

            UReturnVisistChart.Series["Series1"].Color = System.Drawing.Color.FromArgb(int_Red, int_Green, int_Blue);
        }
    }
}